local skel = fk.CreateSkill {
  name = "lb__gubo",
  tags = { Skill.Compulsory },
  derived_piles = "lb__gubo_huixiang"
}

Fk:loadTranslationTable {
  ["lb__gubo"] = "孤波",
  [":lb__gubo"] = "<b>锁定技</b>，" ..
      "游戏开始时，你摸两张牌，然后将两张牌置于武将牌上，称为「<b>回响</b>」。" ..
      "每回合结束时，你观看牌堆顶三张牌，选择其中一张牌并弃置其余牌，" ..
      "将此牌置为「<b>回响</b>」，然后你将「<b>回响</b>」弃至7张。若此牌为装备牌，则你可改为使用之",

  ["#lb__gubo_choose"] = "孤波：请选择其中一张牌并弃置其余牌",
  ["#lb__gubo_use"] = "孤波：你可以使用 %arg",
  ["#lb__gubo_dis"] = "孤波：请弃置%arg张「<b>回响</b>」牌",
  ["#lb__gubo_put"] = "孤波：请将两张牌置入「<b>回响</b>」",

  ["lb__gubo_huixiang"] = "回响",

  ["$lb__gubo1"] = "版本升级？感觉一般。",
  ["$lb__gubo2"] = "这里会有我感兴趣的东西吗？我不信。",
}

skel:addEffect(fk.TurnEnd, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = room:getNCards(3)
    local card = ids[1]
    if #ids > 1 then
      room:moveCards({
        ids = ids,
        toArea = Card.Processing,
        moveReason = fk.ReasonJustMove,
        skillName = skel.name,
        proposer = player,
        moveVisible = false,
      })
      local cards = room:askToChooseCardsAndChoice(player, {
        cards = ids,
        skill_name = skel.name,
        prompt = "#lb__gubo_choose",
      })
      card = table.remove(ids, table.indexOf(ids, cards[1]))
      room:moveCardTo(ids, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "lb__gubo", nil, true, player)
    end
    card = Fk:getCardById(card)
    if card.type == Card.TypeEquip then
      if room:askToUseRealCard(player, {
            pattern = tostring(Exppattern { id = { card.id } }),
            expand_pile = { card.id },
            skill_name = skel.name,
            cancelable = true,
            prompt = "#lb__gubo_use:::" .. card:toLogString(),
          })
      --and room:getCardArea(card) ~= Card.DrawPile
      then
        --room:moveCardTo(card, Card.DrawPile, nil, fk.ReasonJustMove, "lb__gubo", nil, false, player)
        return
      end
    end
    player:addToPile("lb__gubo_huixiang", card, true, skel.name, player)
    local cards = player:getPile("lb__gubo_huixiang")
    local num = #cards - 7
    if num > 0 then
      cards = room:askToCards(player, {
        min_num = num,
        max_num = num,
        skill_name = skel.name,
        pattern = tostring(Exppattern { id = cards }),
        expand_pile = cards,
        prompt = "#lb__gubo_dis:::" .. num,
        cancelable = false,
      })
      if #cards > 0 then
        room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, skel.name, "lb__gubo_huixiang", true,
          player)
      end
    end
  end,
})

skel:addEffect(fk.GameStart, {
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(2, skel.name)
    if player.dead or player:isNude() then return end
    local ids = player:getCardIds("h")
    if #ids > 2 then
      ids = room:askToCards(player, {
        min_num = 2,
        max_num = 2,
        skill_name = skel.name,
        include_equip = true,
        cancelable = false,
        prompt = "#lb__gubo_put",
      })
    end
    if #ids > 0 then
      player:addToPile("lb__gubo_huixiang", ids, true, skel.name, player)
    end
  end,
})

--[[
skel:addEffect("active", {        --------------------------test
  interaction = function (self, player)
    return UI.Spin{from = 1, to = 7}
  end,
  on_use = function (self, room, skillUseEvent)
    local player = skillUseEvent.from
    for i = 1, self.interaction.data, 1 do
      local cid = table.find(room.draw_pile, function (id)
        return Fk:getCardById(id).type ~= Card.TypeEquip
      end)
      if cid then
        player:addToPile("lb__gubo_huixiang", cid, true, skel.name, player)
      end
    end
  end,
})
--]]
return skel
